package com.yeqian.user.handle;

import com.yeqian.entity.ResultJson;
import com.yeqian.user.security.LoginExceptionContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author yeqian
 * @Classname MyAuthenticationFailHandler
 * @Description TODO 登陆失败处理器
 * @Date 2021/5/8 14:58
 */
@Component
@Slf4j
public class YeqAuthenticationFailHandler implements AuthenticationFailureHandler {

    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException {
        ResultJson.writeJSON(response, LoginExceptionContext.getLoginException(exception));
    }
}
